package com.hebeiboruan.userRole.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hebeiboruan.common.uitl.JwtUtils;
import com.hebeiboruan.entity.system.UserRole;
import com.hebeiboruan.userRole.mapper.UserRoleMapper;
import com.hebeiboruan.userRole.service.UserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class UserRoleServiceImpl extends  ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {
    @Override
    public Map getUserRole(HttpServletRequest request) {
        List<UserRole> list=  this.list(new QueryWrapper<UserRole>().eq("`user`", JwtUtils.getUserNo(request)));
        Map map=new HashMap();
        if(list!=null){
            list.forEach(item->{
                map.put(item.getRole().toString(),item.getRole().toString());
            });
        }
        return map;
    }
}

